package bizlogic;

import java.sql.SQLException;
import java.util.ArrayList;
import model.LedgerDTO;
import dao.DAOException;
import dao.DAOFactory;
import dao.LedgerDAO;

public class LedgerManager {
	private LedgerDAO ledgerDAO;

	public LedgerManager() {
		ledgerDAO = DAOFactory.loadInstance().getLedgerDAO();
	}

	@SuppressWarnings("finally")
	public LedgerDTO findLedger(int EmployeeID) {
		LedgerDTO currentLeave = new LedgerDTO();
		try {
			currentLeave = ledgerDAO.findLedger(EmployeeID);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentLeave;
		}
	}
	
	@SuppressWarnings("finally")
	public void addLedger(LedgerDTO oneLedger) {
		LedgerDTO currentLedger = new LedgerDTO();
		try {
			ledgerDAO.addLedger(oneLedger);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 		
	}

	@SuppressWarnings("finally")
	public ArrayList<LedgerDTO> findAllLedger() {
		ArrayList<LedgerDTO> currentList = new ArrayList<LedgerDTO>();
		try {
			currentList = ledgerDAO.findAllLedger();
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			return currentList;
		}
	}
	
	public void updateLedger(LedgerDTO ledger) {
    	try {
			ledgerDAO.updateLedger(ledger);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
	
    public void deleteLedger(LedgerDTO ledger) {
    	try {
			ledgerDAO.deleteLedger(ledger);
		} catch (DAOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
}
